package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.storage.Storage;
import com.cskaoyan.bean.storage.StorageListVO;
import com.cskaoyan.service.ObjectStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/admin/storage")
public class ObjectStorageController {

    @Autowired
    ObjectStorageService objectStorageService;

    @RequestMapping("create")
    public BaseRespVo create(MultipartFile file) {
        Storage storageBean = objectStorageService.create(file);
        return BaseRespVo.ok(storageBean);
    }

    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit,String sort,String order,String key,String name) {
        StorageListVO storageListVO = objectStorageService.list(page,limit,sort,order,key,name);
        return BaseRespVo.ok(storageListVO);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Storage receive) {
        Storage storage = objectStorageService.update(receive);
        return BaseRespVo.ok(storage);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Storage storage) {
        objectStorageService.delete(storage);
        return BaseRespVo.ok();
    }
}
